﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BacteriaSimulation.Simulation
{
    public class UnitVector2D : Vector2D
    {
        /// <summary>
        /// Create a new <code>Versor2D</code> correspondig to the component given as parameters. The vector is created so that 
        /// the magnitude is always 1, no matters what the componets passed in the constructor are
        /// </summary>
        /// <param name="xComponent"></param>
        /// <param name="yComponent"></param>
        public UnitVector2D(Double xComponent, Double yComponent)
        {
            Double fullModule = SimulationPoint.Distance(new SimulationPoint(0, 0), new SimulationPoint(xComponent, yComponent));
            if (fullModule <= 0)
            {
                this.XComponent = 0;
                this.YComponent = 0;
            }
            else
            {
                Double unitVetctorXComponent = xComponent / fullModule;
                Double unitVectorYComponent = yComponent / fullModule;

                this.XComponent = unitVetctorXComponent;
                this.YComponent = unitVectorYComponent;
            }
        }
    }
}
